/**
 * 
 */
package com.zhanggz.mypattern.proxy.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * jdk动态代理
 * 
 * @author alex
 * @Date Jun 27, 2015
 */
public class TimerHandler implements InvocationHandler {
	
	private Object target;
	
	/**
	 * @param target
	 */
	public TimerHandler(Object target) {
		super();
		this.target = target;
	}

	/**
	 * proxy 被代理对象
	 * method 被代理对象的访求
	 * args 方法参数
	 */
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		long starttime = System.currentTimeMillis();
		System.out.println("汽车开始行驶。。。");

		method.invoke(target);

		long endtime = System.currentTimeMillis();
		System.out.println("汽车结束行驶。。。汽车行驶时间：" + (endtime - starttime) + "毫秒！");
		
		return null;
	}

}
